Home:ALL Converter>"last accessed" vs "last modified" file date in java (windows)

"last accessed" vs "last modified" file date in java (windows)

Ask Time:2013-02-11T18:15:02         Author:tajji

Json Formatter

I have a set of files on my windows directory which are copied from elsewhere. On checking the properties of one of the files (right click -> Properties), it shows:

Created: Today, February 11, 2013, 2:51:56 PM

Modified: Tuesday, January 01, 2013, 8:30:04 AM

Accessed: Today, February 11, 2013, 2:51:56 PM

The "Created" and "Accessed" fields basically show the time that the file was actually copied to the new directory, while the "Modified" field shows the modified date of the original file.

In Java on using file.lastModified() what I get back is the "Accessed" (or "Created") timestamp. Is there a way to get the "Modified" value of the original file?

Author:tajji,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/14810033/last-accessed-vs-last-modified-file-date-in-java-windows
Recontemplator :

Along with utilising \"external\" library (like mentioned JavaXT) in Java 7 you can also use new file API (check out this Java 7 nio.2 tutorial). \n\nFile attribFile = new File(\"/tmp/file.txt\");\nPath attribPath = attribFile.toPath();\nBasicFileAttributeView basicView =\n attribPath.getFileAttributeView(BasicFileAttributeView.class);\nBasicFileAttributes basicAttribs = basicView.readAttributes();\n\nSystem.out.println(\"Created: \" + basicAttribs.creationTime());\nSystem.out.println(\"Accessed: \" + basicAttribs.lastAccessTime());\nSystem.out.println(\"Modified: \" + basicAttribs.lastModifiedTime());\n\n\nCheck out this article for extra samples.",
2013-02-11T10:39:31
mjuarez :

You could add this JavaXT library, and then you'll be able to do something like this:\n\njavaxt.io.File file = new javaxt.io.File(\"/tmp/file.txt\");\nSystem.out.println(\"Created: \" + file.getCreationTime());\nSystem.out.println(\"Accessed: \" + file.getLastAccessTime());\nSystem.out.println(\"Modified: \" + file.getLastModifiedTime());\n",
2013-02-11T10:23:37
yy